//
//  ActivityNum.swift
//  LeGou
//
//  Created by lxm on 2022/8/3.
//

import UIKit

class ActivityNum: ZMViewController {

    //MARK:--------------------属性--------------------
    
    //MARK:--------------------UI控件--------------------
    @IBOutlet weak var nav: NavigationBarView!
    
    @IBOutlet weak var goodsContent: UIView!
    
    @IBOutlet weak var totoal: UILabel!
    
    @IBOutlet weak var today: UILabel!
    
    let goods = VIPMallGoodsList().then { vc in
        vc.isGussLike = true
    }
    //MARK:--------------------生命周期--------------------
    override func viewDidLoad() {
        super.viewDidLoad()
        setUI()
        addConstraints()
        bindAction()
        getData()
    }
    //MARK:--------------------UI--------------------
    func setUI() {
        hbd_barHidden = true
        nav.titleLabel.text = "活跃度"
        nav.titleLabel.textColor = .white
        nav.autoBack = true
        
        nav.setRightButton { btn in
            btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
            btn.setTitle("获得规则", for: .normal)
        } _: {
            CommonService.shared.goWeb(type: .activityRules)
        }

        
        addChild(goods)
        goodsContent.addSubview(goods.view)
        goods.view.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    func addConstraints() {
        
    }
    
    //MARK:--------------------methods--------------------
    func bindAction() {
        
    }

    func getData() {
        MineAPI.activityData.rxRequest(type: [String : Any].self).subscribe(onNext:{ [unowned self] resp in
            let json = JSON(resp)
            self.totoal.text = "\(json["totalActivity"].doubleValue.zm.toString(keep: 4))"
            self.today.text  = "\(json["todayActivity"].doubleValue.zm.toString(keep: 4))"
        }, onError: { _ in
            
        }).disposed(by: disposeBag)
    }
    
    @IBAction func onRecord(_ sender: Any) {
        let vc = ActivityRecord()
        self.navigationController?.pushViewController(vc, animated: true)
    }
    //MARK:--------------------delegate--------------------

}
